package com.interagriculture.controller;

import com.interagriculture.annotation.AdminVerify;
import com.interagriculture.common.CustomException;
import com.interagriculture.common.Result;
import com.interagriculture.entity.Project;
import com.interagriculture.enums.ExceptionCodeEnum;
import com.interagriculture.service.ProjectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author 11 2024/11/12
 */
@RestController
@RequestMapping("/adminProject")
public class AdminProjectController {

    @Resource
    private ProjectService projectService;

    @AdminVerify
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Project project){
        projectService.saveOrUpdate(project);
        return Result.ok();
    }

    /**
     * 根据id查询项目
     * @param projectId
     * @return
     */
    @GetMapping("/{projectId}")
    @AdminVerify
    public Result<Project> getById(@PathVariable @NotNull Integer projectId){
        Project project = projectService.queryById(projectId);
        return Result.ok(project);
    }

    @DeleteMapping("/delete")
    @AdminVerify
    public Result deleteById(@RequestParam @NotNull Integer projectId){
        projectService.deleteById(projectId);
        return Result.ok();
    }
}
